#ifndef _KINECT_CONTROLLER_H
#define _KINECT_CONTROLLER_H

#include "SceneImg.h"
#include <XnOpenNI.h>
#include <XnCodecIDs.h>
#include <XnCppWrapper.h>

#define START_CAPTURE_CHECK_RC(rc, what)												\
	if (nRetVal != XN_STATUS_OK)														\
{																					\
	printf("Failed to %s: %s\n", what, xnGetStatusString(rc));				\
	StopCapture();															\
	return ;																	\
}

#define SAMPLE_XML_PATH "../../Data/Sample-User.xml"

#define CHECK_RC(rc, what)											\
	if (rc != XN_STATUS_OK)											\
{																\
	printf("%s failed: %s\n", what, xnGetStatusString(rc));		\
	return rc;													\
}

#define CHECK_ERRORS(rc, errors, what)		\
	if (rc == XN_STATUS_NO_NODE_PRESENT)	\
{										\
	XnChar strError[1024];				\
	errors.ToString(strError, 1024);	\
	printf("%s\n", strError);			\
	return (rc);						\
}

class KinectController
{
	friend class SceneImg;
public:
	KinectController(void);
	~KinectController(void);

public:
	void setSceneImg(SceneImg* sceneImg);

private:
	XnBool g_bPause;
	XnBool g_bRecord;
	XnBool g_bQuit;
	xn::Recorder* g_pRecorder;

	SceneImg* m_sceneImg;

public:
	XnBool g_bCalibrated;

public:
	void StopCapture();
	void CleanupExit();
	void StartCapture();
	void CalibrationEndedCB(xn::SkeletonCapability& skeleton, XnUserID user, XnBool bSuccess, void* cxt);
	void ReadNextData();
	void IdleClean();
	void Pause(){g_bPause = !g_bPause;}
	void RecordChange();

	int KinectInit();
	void RegisterCB();
};

#endif